So a couple of months ago I had a nice conversation with a friend of mine on a sunny day while drinking some coffee. While we were talking he asks me a simple question, how does someone go about measuring the power consumption of an ARM processor on an SBC.
Initially I laughed thinking that he didn't do his research on the topic, there is not way someone didn't do such a thing before, but he just stared at me which was an indicator for what was about to come. Even so I thought of that there must be some long lost piece of software out there that does that job, but there isn't any piece of software that does that he says, he was searching for weeks for that one piece of software but he didn't find any.
So I immidiately thought something not many people know of, RAPL registers, these are special registers in x86 processors that measure the power consumption of the processor, that way I can just write some code that read the RAPL registers and find out the power consumption that way. But here is the funny thing, such a thing does not exist on ARM processors, so I couldn't use the same methodology that I would use for x86 based processors. By that point I was actually starting to get nervous, how can such a simple question be so hard to answer.
Since I could not relly on existing software or existing methodologies I thought of going even lower level, I would use ohms law. I would just get the voltage and resistance of the CPU and with the equation Ampere = Voltage / Resistance I could find out the wattage by multiplying the voltage with the amperes. That seemed promising at first, but anyone with very little experience on how PCBs are made would now that they are almost always multiple layers, so I couldn't just scrape a trace on the top or bottom layer and use that to measure the voltage and resistance. Even if that was the case I would need to have the schematic of the SBC I was going to modify, and even so I am risking ruining the PCB beyond repair.
After that I thought something that many people thought when I originally asked such a question, just use an external tool to measure the power consumption of the PCB, that way you do not have to do any hardware modifications. The problem with this approach is that the we try to measure the power consumption of the CPU, this means that even a 1% error is not acceptable since this can skew the results. Remember, the measurements need to be targetted only to the CPU.
This did get harder now that I expand upon how ruthless this question is, didn't it? A simple answer in hindsight but an impossible one to provide once you take a closer look.
As a last ditch effort I decided to search the internet on information about how much power each instruction for an ARM processors uses and then analyze the individual binaries to calculate its power consumption. Although this would mean I would have to find measurements for each individual ARM processor since different processors consume more or less power than other ARM CPU's I was more than happy to go down that route if it meant solving this problem that quite frankly started getting on my nerves at that point. This would work wonder if such data actually existed and if each instruction always consumed the same amount of power which it doesn't due to Out Of Order execution, cache hits / misses, and even branch predictions amongst other things.
Now, I am quite a stubborn person once I set my mind on to something as many people are, so stubborn in fact that I would think about the solution during work or even during showering. Alas, after two weeks I thought of two methods to measure the power consumption of an ARM processor considering that I cannot do any hardware modifications and that measurements have to be 100% accurate, those methods are.
I have attempted and succeded implementing the second option for the baseline power reading, the result was 4.91 volts at 3.3 micro ampere on the raspberry pi 3, resulting in a baseline power consumption of 0.0000162 watts, this is so that I know how much power is lost due to inefficiencies. Now in the following days I will simply modify the code to hit 100% power usage to one of its cores, then two, then three, and then all four, while having in mind that memory transfers consume more power than simple register data transfers or arithmetic operations. Although this cannot exactly give accurate measurements, especially with cheap hardware, it is a relatively easy method that will work for all SBCs out there, but due to its innacuraccy I only did this as a proof of concept and nothing more.
So this leaves us with only one realistic and accurate method, use the PMIC interface to read how much power is going through it, something so simple I actually did do in python as a proof of concept, here is the source code. This uses the output of the vcgencmd pmic_read_adc on the raspberry pi 5 and displayes the values. FINALLY, A METHOD THAT WORKS ONLY FOR A SINGLE SBC. I now have to write it in C afterwards since this is going to be used in an actual research paper me and some lads are working on about HPC and ARM processor performance per watt.